package com.scy;


import org.apache.commons.codec.binary.Base64;

/**
 * TestString
 *
 * @Author: 马伟奇
 * @CreateTime: 2020-05-05
 * @Description: toString 和 new String 原理和区别
 */
public class TestString {
    public static void main(String[] args) throws Throwable {

        String plainText = "中国,你好,我爱你,abc12345";

        String fileEncoding = System.getProperty("file.encoding");

        System.out.println("file.encoding=" + fileEncoding);

        String base64Encoded_GBK = Base64.encodeBase64String(plainText.getBytes("GBK"));
        System.out.println("gbk密文:" + base64Encoded_GBK);

        String base64Encoded_UTF8 = Base64.encodeBase64String(plainText.getBytes("UTF-8"));
        System.out.println("utf-8密文:" + base64Encoded_UTF8);
        System.out.println("---------------------------------------------------------");
        // 表示密文
        String base64EncodedText_UTF8 = "5Lit5Zu9LOS9oOWlvSzmiJHniLHkvaAsYWJjMTIzNDU=";
        String base64EncodedText_GBK = "1tC5+izE47rDLM7SsK7E4yxhYmMxMjM0NQ==";

        byte[] bytesGBK = Base64.decodeBase64(base64EncodedText_GBK.getBytes("gbk"));
        String s = new String(bytesGBK, "gbk");
        System.out.println(s);

        byte[] bytes = Base64.decodeBase64(base64EncodedText_GBK);
        // 使用base64进行解码
        String rlt1 = new String(bytes);
        // 使用base64进行解码
        String rlt2 = bytes.toString();

        System.out.println("new String===" + rlt1);
        System.out.println("toString==" + rlt2);
    }
}